<?php

class Simpananb_model extends Model {

	var $data;
	
	function Simpananb_model()
	{
		parent::Model();
	}
	
	function set_anggota_id($anggota_id)
	{
		$this->db->where('simpananb.anggota_id', $anggota_id);
	}

	function get_all_data(){
		$this->db->select('simpananb.*, anggota.nama_lengkap as nama_anggota');
		$this->db->from('simpananb');
		$this->db->join('anggota', 'simpananb.anggota_id=anggota.id_anggota', 'INNER');		
		$query = $this->db->get();
		if ($query->num_rows() > 0)
		{
			return $query->result();
		}
		else
		{
			return FALSE;
		}
	}

	function get_last_id(){
		$query = $this->db->query('select * from simpananb order by id desc limit 1 ');
		if ($query->num_rows() > 0)
		{
			return $query->row();
		}
		else
		{
			return FALSE;
		}
	}
	
	function get_data_by_id($id){
		$this->db->select('simpananb.*, anggota.nama_lengkap as nama_anggota');
		$this->db->from('simpananb');
		$this->db->join('anggota', 'simpananb.anggota_id=anggota.id_anggota', 'INNER');
		$this->db->where('simpananb.id', $id);
		$query = $this->db->get();
		if ($query->num_rows() > 0)
		{
			return $query->row_array();
		}
		else
		{
			return FALSE;
		}
	}

	function fill_data()
	{
//		echo 'hoho';
//		echo $this->input->post('anggotaID');
		//$status = ($this->input->post('status')) ? $this->input->post('status') : 'Start';
		$this->data = array(
			'nama_simpananb' => $this->input->post('nama_simpananb'),
			'anggota_id' => $this->input->post('anggotaID'),
			'masa_simpanan' => $this->input->post('masa_simpanan'),			
			'tgl_reg' => $this->input->post('tgl_reg'),
			'biaya' => $this->input->post('biaya'),
			'tgl_mulai' => $this->input->post('from'),
			'tgl_jatuh_tempo' => $this->input->post('tgl_jatuh_tempo'),			
			'keterangan' => $this->input->post('keterangan'),
			'periode' => $this->input->post('periode'),
			'setoran' => $this->input->post('setoran'),
			'bunga_persen' => $this->input->post('bunga_persen'),
			'bunga' => $this->input->post('bunga'),
			'administrasi_persen' => $this->input->post('administrasi_persen'),
			'administrasi' => $this->input->post('administrasi'),
			'total' => $this->input->post('total'),
			'bunga_per_bulan' => $this->input->post('bunga_per_bulan'),
			'total_bunga' => $this->input->post('total_bunga'),
			'jenis_agunan' => $this->input->post('jenis_agunan'),
			'no_bpkb' => $this->input->post('no_bpkb'),
			'roda' => $this->input->post('roda'),
			'merk' => $this->input->post('merk'),
			'no_rangka' => $this->input->post('no_rangka'),
			'no_mesin' => $this->input->post('no_mesin'),
			'no_polisi' => $this->input->post('no_polisi'),
			'tahun_perakitan' => $this->input->post('tahun_perakitan'),
			'nama_pemilik' => $this->input->post('nama_pemilik')
		);
	}
	
	//Check for duplicate login ID
	function check_name($id = '')
	{
		$this->db->where('nama_simpananb', $this->data['nama_simpananb']);
		if($id != '') $this->db->where('id !=', $id);
		$query = $this->db->get('simpananb');

		if ($query->num_rows() > 0)
		{
			return FALSE;
		}
		else
		{
			return TRUE;
		}
	}	

	function insert_data()
	{
		$insert = $this->db->insert('simpananb', $this->data);
		return $insert;
	}

	function update_data($id)
	{
		$this->db->where('id', $id);
		$update = $this->db->update('simpananb', $this->data);
		return $update;
	}

	function delete_data($id){
		$this->db->where('id', $id);
		$delete = $this->db->delete('simpananb');
		return $delete;
	}

}

/* End of file simpananb_model.php */
/* Location: ./application/models/simpananb_model.php */
